public class ExtendsDemo18 {
    public static void main(String[] args) {
        Pig pig = new Pig();
        pig.setAge(10);
        pig.setName("荷兰猪");

        Cat cat = new Cat();
        cat.setAge(10);
        cat.setName("加菲猫");

        // 实现代码复用

        cat.eat();
    }
}


class Animal {
    private String name;
    private int age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void eat() {
        System.out.println("吃");
    }
}


class Pig extends Animal {
    // 父类的行为满足不了子类，那么我们就重写

    @Override
    public void eat() {
        System.out.println("猪吃玉米");
    }
}

class Cat extends Animal {
    @Override
    public void eat() {

        System.out.println("吃国产猫粮");
    }
}
